package com.tfswx.jcyw.ruleenginedesigner.api;

import com.tfswx.jcyw.ruleenginedesigner.bean.ApiResult;
import com.tfswx.jcyw.ruleenginedesigner.dto.xmgl.*;
import com.tfswx.jcyw.ruleenginedesigner.service.XmglService;
import com.tfswx.ruleengine.database.dto.GzImportOutputDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/5/11
 */
@RestController
@RequestMapping("/xmgl")
@Api(tags = "项目管理")
public class XmglController {

    @Resource
    private XmglService xmglService;

    @ApiOperation("获取项目列表")
    @PostMapping("/queryXmListByRybm")
    public ApiResult<List<XmListByRybmQueryOutputDTO>> queryXmListByRybm(@NonNull @RequestBody @Validated XmListByRybmQueryInputDTO xmListByRybmQueryInputDTO) {
        List<XmListByRybmQueryOutputDTO> xmList = xmglService.queryXmListByRybm(xmListByRybmQueryInputDTO);
        return ApiResult.success(xmList);
    }

    @ApiOperation("根据项目编码获取项目")
    @PostMapping("/queryXmByXmbm")
    public ApiResult<XmByXmbmQueryOutputDTO> queryXmByXmbm(@NonNull @RequestBody @Validated XmByXmbmQueryInputDTO xmByXmbmQueryInputDTO) {
        XmByXmbmQueryOutputDTO xm = xmglService.queryXmByXmbm(xmByXmbmQueryInputDTO);
        return ApiResult.success(xm);
    }


    @ApiOperation("添加项目")
    @PostMapping("/addXm")
    public ApiResult<String> addXm(@NonNull @RequestBody @Validated XmAddInputDTO xmAddInputDTO) {
        String xmbm = xmglService.addXm(xmAddInputDTO);
        return ApiResult.success(xmbm);
    }

    @ApiOperation("修改项目")
    @PostMapping("/updateXm")
    public ApiResult<Boolean> updateXm(@NonNull @RequestBody @Validated XmUpdateInputDTO xmUpdateInputDTO) {
        boolean isSucc = xmglService.updateXm(xmUpdateInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("恢复项目")
    @PostMapping("/undeleteXm")
    public ApiResult<Boolean> undeleteXm(@NonNull @RequestBody @Validated XmUndeleteInputDTO xmUndeleteInputDTO) {
        boolean isSucc = xmglService.undeleteXm(xmUndeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("删除项目")
    @PostMapping("/deleteXm")
    public ApiResult<Boolean> deleteXm(@NonNull @RequestBody @Validated XmDeleteInputDTO xmDeleteInputDTO) {
        boolean isSucc = xmglService.deleteXm(xmDeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("导出规则")
    @PostMapping(value = "/dcGz")
    public ApiResult<String> dcGz(@RequestBody @Validated GzDcInputDTO gzDcInputDTO) throws IOException {
        String p = xmglService.dcGz(gzDcInputDTO);
        return ApiResult.success(p);
    }

    @ApiOperation("导入规则")
    @PostMapping(value = "/drGz")
    public ApiResult<GzImportOutputDTO> drGz(@Validated GzDrInputDTO gzDrInputDTO) throws IOException {
        GzImportOutputDTO gzImportOutputDTO = xmglService.drGz(gzDrInputDTO);
        return ApiResult.success(gzImportOutputDTO);
    }

    @ApiOperation("清空项目规则")
    @PostMapping(value = "/qkxmgz")
    public ApiResult<XmgzQkOutputDTO> qkxmgz(@RequestBody @Validated XmgzQkInputDTO xmgzQkInputDTO) {
        XmgzQkOutputDTO xmgzQkOutputDTO = xmglService.qkXmgz(xmgzQkInputDTO);
        return ApiResult.success(xmgzQkOutputDTO);
    }

    @ApiOperation("彻底删除项目及相关内容")
    @PostMapping(value = "/cdscXm")
    public ApiResult<Boolean> cdscXm(@RequestBody @Validated XmCdscInputDTO xmCdscInputDTO) {
        boolean isSucc = xmglService.cdscXm(xmCdscInputDTO);
        return ApiResult.success(isSucc);
    }
}
